
// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple 3D project that uses Dark GDK
// it can be used as a starting point in making your own 3D games

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "splash_screen.cpp"
#include "game_interface.cpp"
#include "economy.cpp"

// the main entry point for the application is this function
void DarkGDK ( void )
{
	// in this application we are going to create some 3D objects
	// and position them on screen

	// when starting a Dark GDK program it is useful to set global
	// application properties, we begin by turning the sync rate on,
	// this means we control when the screen is updated, we also set
	// the maximum rate to 60 which means the maximum frame rate will
	// be set at 60 frames per second
	dbSyncOn   ( );
	dbSyncRate ( 60 );
	splash_screen selection_screen;
	game_interface game_ui; 
	economy money;
	dbSetDisplayMode ( 800, 600, 32 );
	int right_button_id;

	// set our random seed to a value from the timer, this will help
	// to ensure each time we run our program the random values appear
	// more random
	dbRandomize ( dbTimer ( ) );


	//start the splash screen
	selection_screen.load_splash_images();
	while(selection_screen.show_splash() == 0) {
		dbSync();
	}

	// make some 3D objects
	for ( int i = 1; i < 50; i++ )
	{
		// make spheres and stuff o.o
		dbMakeObjectSphere ( i, 1 );
		dbPositionObject ( i, dbRnd ( 20 ), dbRnd ( 20 ), dbRnd ( 20 ) );
		dbScaleObject ( i, 100 + dbRnd ( 400 ), 100 + dbRnd ( 400 ), 100 + dbRnd ( 400 ) );
		dbColorObject ( i, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
		dbSetObjectSpecularPower ( i, 255 );
		dbSetObjectAmbient ( i, 0 );
	}

	// move our camera back so we can view the objects
    dbMakeCamera(1);
    dbPositionCamera ( 1, 10, 10, -20 );

	game_ui.create_interface();
	money.create_economy();
	
	
	// now we come to our main loop, we call LoopGDK so some internal
	// work can be carried out by the GDK	
	while ( LoopGDK ( ) )
	{
        right_button_id = game_ui.interface_loop(); 
		money.display_money();

		money.set_money(right_button_id);

		// move the camera forwards
		if( dbUpKey() ) {
			dbPositionCamera(1, dbCameraPositionX(1), dbCameraPositionY(1) + 1, dbCameraPositionZ(1) );			  
		}
		// move the camera backwards
		if( dbDownKey() )
			dbPositionCamera(1, dbCameraPositionX(1), dbCameraPositionY(1) - 1, dbCameraPositionZ(1) );				

		// move the camera left
		if( dbLeftKey() )
			dbPositionCamera(1, dbCameraPositionX(1) - 1, dbCameraPositionY(1), dbCameraPositionZ(1) );	

		if( dbRightKey() )
			dbPositionCamera(1, dbCameraPositionX(1) + 1, dbCameraPositionY(1), dbCameraPositionZ(1) );	

		// rotate all of our objects
		for( int i = 1; i < 50; i++ )
			dbRotateObject( i, dbObjectAngleX ( i ) + 0.1, dbObjectAngleY ( i ) + 0.2, dbObjectAngleZ ( i ) + 0.3 );

		// rotate all of our objects
		for ( int i = 1; i < 50; i++ )
			dbRotateObject ( i, dbObjectAngleX ( i ) + 0.1, dbObjectAngleY ( i ) + 0.2, dbObjectAngleZ ( i ) + 0.3 );
		
		// here we make a call to update the contents of the screen
		dbSync ( );
	}

	// before quitting delete our objects
	for ( int i = 1; i < 50; i++ )
		dbDeleteObject ( i );

	// and now everything is ready to return back to Windows
	return;
}